package com.cilico.components;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;

import com.cilico.ConfigManager;
import com.cilico.R;
import com.cilico.utils.ConstantRepository;
import com.cilico.utils.Utils;
import com.cilico.utils.StringTicker;
import com.cilico.view.BaseView;
import com.cilico.view.FormLayout;
import com.cilico.view.SegmentLinearLayout;

public class Radio extends RadioButton implements Component {
	FormLayout formLayout_;
	public CssStyle cssStyle_;

	// 带segment属性的该控件获得焦点是的图标对象
	Bitmap activityIcon_;
	// 带segment属性的该控件未获得焦点是的图标对象
	Bitmap inactivityIcon_;
	// 带segment属性控件的实际宽度
	int segmentWidth_;
	// segment序号，主要用于绘制带有segment属性按钮的效果，予以标记
	int segmentIndex_;
	// 绘制圆角矩形背景时的转角半径
	final int xRadius_ = 10;
	final int yRadius_ = 10;
	private int TEXT_MARGIN = 10; // will add image width
	int textColor_;
	String text_;
	public String groupName_;
	public boolean isChecked_;
	boolean focus_;
	public boolean attrSave_;
	int width_;
	int height_;
	int left_; // Relative left position to the left of the FULL canvas.
	int top_; // Relative left position to the top of the FULL canvas.
	public String backValue_;
	/**
	 * Margins used when rendering text.
	 */
	protected static final int Y_MARGIN = 5;
	String time_ = "1";//此属性只用来标记是否要自动局部更新当前页面的某些内容
	String selectSort_;
	public String sortKey_;
	public String attrName_;
	public String attrValue_;
	public String attrSearchkey_;
	public String attrSegment_;
	// 存储关联属性，此对象记录需联动存储的控件名称
	public String attrReitem;
	public String isEncrypt_;
	public String[] relaEnable_;
	public String[] relaDisable_;
	public String[] relaVisible_;
	public String[] relaInvisible_;
	// 绘制内容字体样式设置类
	TextPaint paint_;
	// 添加该控件的界面类
	BaseView bv_;

	private boolean isInTable_;

	/**
	 * @param context
	 * @param text
	 * @param f
	 * @param groupName
	 */
	public Radio(Context context, String text, TextPaint f, String groupName, String selectSort, String sortKey) {
		super(context);
		bv_ = (BaseView) context;
		// TODO Auto-generated constructor stub
		init();
		// 设置单选按钮显示文字
		this.setText(text);
		// 设置单选按钮高度
		if (null == f) {
			f = new TextPaint();
			f.setTextSize(Utils.getScaledValue(ConfigManager.SIZE_SMALL));
			f.setTypeface(Typeface.DEFAULT);
		}
		paint_ = f;
		paint_.setTextSize(Utils.getScaledValue(ConfigManager.SIZE_SMALL));
		width_ = MAX_WIDTH;
		height_ = (int) (paint_.getTextSize() + (Y_MARGIN << 1));
		// 将该控件设置为未选中
		this.setChecked(false);
		// 设置单选按钮传递键值
		groupName_ = groupName;
		// 国航项目将单选按钮改为与table联动，通过sortkey选择联动方式
		selectSort_ = selectSort;
		sortKey_ = sortKey;
		this.setFocusableInTouchMode(true);
		ConstantRepository.getRadioBoxIcon(true, bv_);
	}

	static Radio createRadio(Context context, String text, TextPaint f, String groupName, String selectSort, String sortKey) {
		Radio radio = new Radio(context, text, f, groupName, selectSort, sortKey);
		return radio;
	}

	private void init() {
		this.clearFocus();
		this.setFocusable(true);
	}

	public String getContentText() {
		return super.getText().toString();
	}

	public void setContentText(String text) {
		// TODO Auto-generated method stub
		this.setText(text);
	}

	void settleComponets(BaseView bv) {
		this.settleComponetsRadio(bv, 0);
	}

	public void settleComponetsRadio(BaseView bv, int index) {
		Utils.settleComponetsChild(bv, this.isChecked(), relaEnable_, relaDisable_, relaVisible_, relaInvisible_,
				this);
	}

	public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		setMeasuredDimension(width_, height_);
	}

	protected void onDraw(Canvas g) {
		if (null != this.attrSegment_)
			paintSegment(g, this.left_, this.top_);
		else if (null != this.attrSearchkey_)
			paintSearchKey(g, this.left_, this.top_);
		else
			paintText(g, this.left_, this.top_);
	}

	// 绘制带有searchkey属性的控件效果
	private void paintSearchKey(Canvas g, int x, int y) {
		try {
			textColor_ = getTextColors().getDefaultColor();
		} catch (Exception e) {
			textColor_ = getCurrentTextColor();
		}
		paint_.setColor(textColor_);
		paint_.setAntiAlias(true);
		int h = getIconSize();
		x += h + TEXT_MARGIN;
		// TODO Auto-generated method stub
		if (this.getText() != null) {
			text_ = this.getText().toString();
			BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
			if (focus_) {
				paint_.setColor(BaseView.HL_BACKGROUND_COLOR);
				int w = (int) ((paint_.measureText(text_) + x) < (width_ - h - 10) ? paint_.measureText(text_) + x
						: (width_ - h - 10));
				paint_.setStyle(Style.FILL);
				g.drawRect(x, y, w + x, h + y + 2, paint_);
				BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
				StringTicker.instance().drawMoveStr(this, g, w, paint_, textColor_, text_, x, y + h);
			}
			if (this.isFocused()) {
				paint_.setColor(BaseView.HL_BACKGROUND_COLOR);
				int w = (int) ((paint_.measureText(text_) + x) < (width_ - h - 10) ? paint_.measureText(text_) + x
						: (width_ - h - 10));
				paint_.setStyle(Style.FILL);
				g.drawRect(x, y, w + x, h + y + 2, paint_);
				BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
				StringTicker.instance().drawMoveStr(this, g, w, paint_, textColor_, text_, x, y + h);
			} else {
				BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
				g.drawText(Utils.abbrevString(text_, paint_, width_ - h - 10), x, y + h, paint_);
			}
		}
	}

	// 绘制带有segment属性的控件效果
	private void paintSegment(Canvas g, int left, int top) {
		// 管理器的大小即为带有segment属性radio控件的总数个数
		// TODO Auto-generated method stub
		// 设置字体非抗锯齿效果，使字体边界更平滑
		paint_.setAntiAlias(true);
		BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
		if (this.isChecked()) {
			g.drawBitmap(activityIcon_, left, top, paint_);
//			paint_.setColor(BaseView.HL_SEGMENTRADIO);
			paint_.setColor(Color.WHITE);
		} else {
			g.drawBitmap(inactivityIcon_, left, top, paint_);
			paint_.setColor(BaseView.UN_SEGMENTRADIO);
		}
		// 画字体的时候去掉渐变效果
		if (this.getText() != null) {
			text_ = this.getText().toString();
			paint_.setTypeface(Typeface.DEFAULT);
			int xText = left + ((segmentWidth_ - (int) paint_.measureText(text_)) >> 1);
			int yText = top + ((activityIcon_.getHeight() + (int) paint_.getTextSize()) >> 1) - 2;
			BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
			g.drawText(text_, xText, yText, paint_);
		}
	}

	private int getIconSize() {
		return (int) (paint_.getTextSize());
	}

	/**
	 * Derived class may change how text is drawn.
	 */
	protected void paintText(Canvas g, int x, int y) {
		// 设置字体非抗锯齿效果，使字体边界更平滑
		paint_.setAntiAlias(true);
		try {
			textColor_ = getTextColors().getDefaultColor();
		} catch (Exception e) {
			textColor_ = getCurrentTextColor();
		}
		paint_.setColor(textColor_);
		int h = getIconSize();
		Bitmap temp;

		try {
			if (this.isChecked())
				temp = ConstantRepository.radioImg_;
			else
				temp = ConstantRepository.unRadioImg_;
			if (temp != null) {
				g.drawBitmap(temp, x + h / 4, y + ((height_ - temp.getHeight()) >> 1), paint_);
				h = temp.getWidth();
			} else {
				// 初始化最外圆半径
				int maxRadius;
				if (h <= (ConfigManager.minRadius_ << 1)) {
					maxRadius = ConfigManager.minRadius_;
				} else {
					maxRadius = (h - 4) >> 1;
				}
				// 初始化圆心坐标
				int xCircle = x + h >> 2 + maxRadius;
				int yCircle = y + height_ - (h >> 1);
				// 填充最外层圆
				paint_.setColor(ConfigManager.COLOR_OUTERMOST);
				paint_.setStyle(Style.FILL);
				g.drawCircle(xCircle, yCircle, maxRadius, paint_);
				// 绘制中圆阴影
				// 该构造函数两个x参数相同表示进行垂直渐变
				Shader shader_ = new LinearGradient(0, yCircle - (maxRadius - 1), 0, yCircle + (maxRadius - 1),
						new int[] { ConfigManager.COLOR_DKGRAY, ConfigManager.COLOR_WHITE }, null,
						Shader.TileMode.MIRROR);
				paint_.setShader(shader_);
				paint_.setStyle(Style.STROKE);
				g.drawCircle(xCircle, yCircle, maxRadius - 1, paint_);
				// 内圆半径
				int radiusMin = maxRadius - 2;
				// 效果偏移值，该类变量纯粹为渐变的时候排列偏移植
				int offset = radiusMin / 3;
				int offsetU = offset << 1;

				if (this.isChecked()) {
					// 控件被选中
					shader_ = new LinearGradient(0, yCircle - radiusMin + offset, 0, yCircle + radiusMin + offset,
							new int[] { ConfigManager.COLOR_GREEN, ConfigManager.COLOR_DKGREEN }, null,
							Shader.TileMode.MIRROR);
					paint_.setShader(shader_);
					g.drawCircle(xCircle, yCircle, radiusMin, paint_);
				} else {
					// 控件未获得焦点
					shader_ = new LinearGradient(0, yCircle - radiusMin + offsetU, 0, yCircle + radiusMin + offsetU,
							new int[] { ConfigManager.COLOR_GRAY, ConfigManager.COLOR_WHITE }, null,
							Shader.TileMode.MIRROR);
					paint_.setShader(shader_);
					g.drawCircle(xCircle, yCircle, radiusMin, paint_);
				}

				paint_.setStyle(Style.STROKE);
				paint_.setShader(null);

				if (focus_) {
					// 控件获得焦点,增加一个外边框
					paint_.setColor(ConfigManager.COLOR_GREEN);
					g.drawCircle(xCircle, yCircle, maxRadius + 1, paint_);
				}
				if (this.isFocused()) {
					// 控件获得焦点,增加一个外边框
					paint_.setColor(ConfigManager.COLOR_GREEN);
					g.drawCircle(xCircle, yCircle, maxRadius + 1, paint_);
				}

				paint_.setColor(ConfigManager.COLOR_GRAY);
				g.drawCircle(xCircle, yCircle, radiusMin, paint_);
			}
		} catch (Exception ex) {
			Utils.printException(ex);
		}
		x += h + TEXT_MARGIN;
		if ((this.getText() != null) && !this.getText().equals("")) {
			text_ = this.getText().toString();
			BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
			if (focus_) {
				paint_.setColor(BaseView.HL_BACKGROUND_COLOR);
				int w = (int) ((paint_.measureText(text_) + x) < (width_ - h - 10) ? paint_.measureText(text_) + x
						: (width_ - h - 10));
				paint_.setStyle(Style.FILL);
				g.drawRect(x, y, w + x, h + y + 2, paint_);
				StringTicker.instance().drawMoveStr(this, g, w, paint_, textColor_, text_, x, y + h);
			}
			if (this.isFocused()) {
				paint_.setColor(BaseView.HL_BACKGROUND_COLOR);
				int w = (int) ((paint_.measureText(text_) + x) < (width_ - h - 10) ? paint_.measureText(text_) + x
						: (width_ - h - 10));
				paint_.setStyle(Style.FILL);
				g.drawRect(x, y, w + x, h + y + 2, paint_);
				BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
				StringTicker.instance().drawMoveStr(this, g, w, paint_, textColor_, text_, x, y + h);
			} else {
				BaseView.setTypeFace(paint_, cssStyle_ != null ? cssStyle_.fontWeight_ : null);
				g.drawText(Utils.abbrevString(text_, paint_, width_ - h - 10), x, y + h, paint_);
			}
		}
	}

	// 焦点改变时调用该方法
	protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
		if (gainFocus) {
			BaseView bv = (BaseView) this.getContext();
			bv.stopTicker();
		}
		super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
	}

	boolean keyGameAction(int keyCode) {
		if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
			pointerPressed(0, 0);
		}
		return false;
	}

	void pointerPressed(int x, int y) {
		setCheckedManually(true);
		// 重新设置控件联动
		Utils.settleComponets((BaseView) this.getContext());
		bv_.llScreen_.invalidate();
	}

	public boolean onTouchEvent(MotionEvent me) {
		// 取得触摸动作类型
		int action = me.getAction();
		switch (action) {
		case KeyEvent.ACTION_DOWN:
			this.requestFocus();
			break;
		case KeyEvent.ACTION_UP:
			if (null != this.attrSearchkey_) {
				this.setSelectView();
			} else if (null != this.selectSort_) {
				int viewCount = bv_.vWidgetArray_.size();
				Table table = null;
				Object o = null;
				for (int i = 0; i < viewCount; i++) {
					o = bv_.vWidgetArray_.elementAt(i);
					if (o instanceof Table) {
						table = (Table) o;
						if (null != table && null != table.attrName_ && table.attrName_.equals(selectSort_)) {
							break;
						}
					}
				}
				this.keyGameAction(KeyEvent.KEYCODE_DPAD_CENTER);
			} else {
				this.keyGameAction(KeyEvent.KEYCODE_DPAD_CENTER);
			}
			break;
		default:
			return super.onTouchEvent(me);
		}
		return true;
	}

	private void setSelectView() {
		try {
			Select.Option lpo = new Select.Option(bv_, this.text_);
			lpo.setValue(this.attrValue_);
			Select.ISRUNNING = false;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
	}

	public void shrinkWidth() {
		// TODO Auto-generated method stub

	}

	public void cleanText() {
		// TODO Auto-generated method stub

	}

	public void setFocus(boolean isFocus, int i) {
		// TODO Auto-generated method stub
		focus_ = isFocus;
	}

	/**
	 * Checks all the radios in the view, and sets those in the same group unchecked.
	 */
	private void resetMutex() {
		final BaseView bv = ((BaseView) this.getContext());
		ViewGroup vg = (ViewGroup) this.getParent();
		if (vg instanceof SegmentLinearLayout) {
			final SegmentLinearLayout sll = (SegmentLinearLayout) vg;
			final int sizeTemp = sll.getChildCount();
			bv.runOnUiThread(new Runnable() {

				public void run() {
					// TODO Auto-generated method stub
					for (int j = 0; j < sizeTemp; j++) {
						Radio lpr = (Radio) sll.getChildAt(j);
						/**
						 * 如果一个界面存在多个segment控件组且每个控件组都有不同的组名则使用该判断条件 if (lpr.groupName_ != null &&
						 * lpr.groupName_.equals(groupName_))
						 */

						lpr.setChecked(false);
						lpr.invalidate();

					}
				}

			});

			return;
		} else {
			final int size = bv.vWidgetArray_.size();
			bv.runOnUiThread(new Runnable() {

				public void run() {
					// TODO Auto-generated method stub
					for (int i = 0; i < size; i++) {
						Object o = (Object) bv.vWidgetArray_.elementAt(i);
						if (null == o)
							continue;
						if (o instanceof Wrap)
							continue;
						if (o instanceof Radio) {
							Radio r = (Radio) o;
							if (r.groupName_ != null && r.groupName_.equals(groupName_)) {
								r.setChecked(false);
								r.invalidate();
							}
						}
					}
				}

			});

		}
	}

	/** clear check radio by groupName_ */
	public void setCheckedManually(final boolean isChecked) {
		// 将所有在同一组里的radio的isChecked_重置为false
		if (this.getParent() instanceof SegmentLinearLayout) {
			SegmentLinearLayout sll = (SegmentLinearLayout) this.getParent();
			for (int i = sll.getChildCount() - 1; i >= 0; i--) {
				((Radio) sll.getChildAt(i)).isChecked_ = false;
			}
		}

		if (isChecked) {
			resetMutex();
			this.settleComponets(bv_);
		}
		isChecked_ = isChecked;
		BaseView bv = (BaseView) this.getContext();
		bv.runOnUiThread(new Runnable() {

			public void run() {
				// TODO Auto-generated method stub
				setChecked(isChecked);
			}

		});

		if (time_ != null) {//如果等于null，那么说明这个radio不是用来控制自动刷新的，也就不用去改变控制是否自动更新的变量
			BaseView.wantToUpdateTable_ = time_;
		}
	}

	public void mould() {
		CssStyle cs = cssStyle_;
		// set the font size.
		if (cs != null && cs.fontSize_ > 0) {
			setTextSize(cs.fontSize_);
			paint_.setTextSize(cs.fontSize_);
		}
		// set the height
		if (cs != null && cs.height_ > 0) {
			setHeight(cs.height_);
			height_ = cs.height_;
		}
		// set the width.
		if (cs != null && cs.width_ > 0) {
			setWidth(cs.width_);
			width_ = cs.width_;
		} else {
			if (null != this.attrSegment_) {
				// 如果存在segment属性，且服务端未指定宽
				width_ = MAX_WIDTH;
			} else {
				int widthImg;
				if (null != ConstantRepository.radioImg_) {
					widthImg = ConstantRepository.radioImg_.getWidth();
				} else {
					widthImg = ConfigManager.minRadius_;
				}
				width_ = (int) (this.left_ + TEXT_MARGIN + widthImg + paint_.measureText(this.getText().toString()));
			}
		}

		if (null != this.attrSegment_) {
			// 说明该控件存在segment属性
			setSegmentIcon();
			setSegmentHeight(height_);
			setSegmentWidth(width_);
			setSegmentCS(cssStyle_);
		}
		// set the text color.
		if (cs != null && cs.fgColor_ != 0) {
			setTextColor(cs.fgColor_);
		}
		// set the font family (since API Level 4)
		/*
		 * String fontPath = ConfigManager.getFontPath(cbStyle.fontFamily_); if (fontPath != null) {
		 * temp.setTypeface(Typeface.createFromFile(fontPath)); }
		 */

		// set the background color.
		if (cs != null && cs.bgColor_ != 0) {
			setBackgroundColor(cs.bgColor_);
		}

		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width_, height_);
		setLayoutParams(lp);
	}

	private void setSegmentCS(CssStyle cssStyle) {
		// TODO Auto-generated method stub
		SegmentLinearLayout sll = (SegmentLinearLayout) this.getParent();
		// 该高度在segmeng加到rowpanel时会用到
		sll.setCssStyle(cssStyle);
	}

	private void setSegmentWidth(int width) {
		// TODO Auto-generated method stub
		SegmentLinearLayout sll = (SegmentLinearLayout) this.getParent();
		// 该高度在segmeng加到rowpanel时会用到
		sll.setCmpWidth(width * sll.getChildCount());
	}

	/**
	 * + * 设置父类管理器segmenglayout的高度 +
	 */
	private void setSegmentHeight(int height) {
		// TODO Auto-generated method stub
		SegmentLinearLayout sll = (SegmentLinearLayout) this.getParent();
		// 该高度在segmeng加到rowpanel时会用到
		sll.setCmpHeidht(height);
	}

	// 设置有segment属性单选的背景图片
	private void setSegmentIcon() {
		Bitmap segmentAllImg = null;
		// TODO Auto-generated method stub
		segmentAllImg = ConstantRepository.decodeBitmap(bv_.getResources(), R.drawable.segment_radio_all);

		if (null != segmentAllImg) {
			activityIcon_ = Bitmap.createBitmap(segmentAllImg, 0, 0, segmentAllImg.getWidth() >> 1,
					segmentAllImg.getHeight());
			inactivityIcon_ = Bitmap.createBitmap(segmentAllImg, (segmentAllImg.getWidth() >> 1) + 1, 0,
					(segmentAllImg.getWidth() >> 1) - 1, segmentAllImg.getHeight());
			if (!segmentAllImg.isRecycled()) {
				segmentAllImg.recycle();
			}
			segmentAllImg = null;
			// 如果服务端未指定高，则按图片高计算
			if (cssStyle_ != null && cssStyle_.height_ > 0) {
				setHeight(cssStyle_.height_);
				height_ = cssStyle_.height_;
			} else {
				height_ = activityIcon_.getHeight();
			}
		}

		View view = (View) this.getParent();
		if (view instanceof SegmentLinearLayout) {
			SegmentLinearLayout sll = (SegmentLinearLayout) view;
			int sizeSegment = sll.getChildCount();
			try {
				this.segmentWidth_ = this.width_ / sizeSegment;
				this.width_ = this.segmentWidth_;
				activityIcon_ = makeSegmentRadio(activityIcon_, this.segmentWidth_, sizeSegment);
				activityIcon_ = Bitmap.createScaledBitmap(activityIcon_, this.segmentWidth_, this.height_, true);
				inactivityIcon_ = makeSegmentRadio(inactivityIcon_, this.segmentWidth_, sizeSegment);
				inactivityIcon_ = Bitmap.createScaledBitmap(inactivityIcon_, this.segmentWidth_, this.height_, true);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				Utils.printException(e);
			}
		}
	}

	Bitmap makeSegmentRadio(Bitmap imgOri, int width, int segMentSum) throws Exception {
		int ori_w = imgOri.getWidth();
		int ori_h = imgOri.getHeight();
		int[] ori_rgb = new int[ori_w * ori_h];
		int[] dst_rgb = new int[width * ori_h];

		int dst = 0;
		int src = 0;
		imgOri.getPixels(ori_rgb, 0, ori_w, 0, 0, ori_w, ori_h);

		int middle = width - ori_w;
		// Copy the first 6 columns from the ori image to the left border.
		for (int i = 0; i < ori_h; ++i) {
			if (i > 0) {
				src = i * ori_w;
			}

			if (this.segmentIndex_ == 1) {
				// 绘制带有segment属性组的第一个控件
				for (int j = 0; j < ori_w; ++j) {
					dst_rgb[dst++] = ori_rgb[src++];
				}
				src -= 1;
				// Copy background from the 6-th column of the source image.
				for (int j = ori_w; j < width; ++j) {
					dst_rgb[dst++] = ori_rgb[src];
				}
			} else if (this.segmentIndex_ == segMentSum) {
				// 绘制带有segment属性组的最后一个控件

				for (int j = 0; j < ori_w; ++j) {
					src++;
				}
				src -= 1;
				// Copy background from the 6-th column of the source image.
				for (int j = 0; j < middle; ++j) {
					dst_rgb[dst++] = ori_rgb[src];
				}
				// Copy the reverse of ori image to the right border.
				for (int j = middle; j < width; ++j) {
					dst_rgb[dst++] = ori_rgb[src--];
				}
			} else {
				for (int j = 0; j < ori_w; ++j) {
					src++;
				}
				src -= 1;
				for (int j = 0; j < width; ++j) {
					dst_rgb[dst++] = ori_rgb[src];
				}
			}
		}
		Bitmap imgDst = null;
		imgDst = Bitmap.createBitmap(dst_rgb, width, ori_h, Bitmap.Config.ARGB_8888);
		return imgDst;
	}

	public void setCmpHeidht(int height) {
		// TODO Auto-generated method stub

	}

	public void setCmpWidth(int width) {
		// TODO Auto-generated method stub

	}

	public void setCssStyle(CssStyle style) {
		cssStyle_ = style;
	}

	public View getCmpView() {
		return this;
	}

	public int getCmpHeight() {
		return height_;
	}

	public int getCmpWidth() {
		// TODO Auto-generated method stub
		return width_;
	}

	public void setInTable(boolean inTable) {
		isInTable_ = inTable;
	}

	public boolean isInTable() {
		return isInTable_;
	}

	public CssStyle getCssStyle() {
		return cssStyle_;
	}

	public void releaseResource(View view) {
		// TODO Auto-generated method stub
		/**
		 * 此两张图用于带segment属性的按钮，由于该项目中此控件位于一个可存储界面，所以不宜贸然置空，置空操作待定
		 */
		if (null != activityIcon_ && !activityIcon_.isRecycled()) {
			activityIcon_.recycle();
		}
		activityIcon_ = null;
		if (null != inactivityIcon_ && !inactivityIcon_.isRecycled()) {
			inactivityIcon_.recycle();
		}
		inactivityIcon_ = null;

		// text_ = null;
		// groupName_ = null;
		// attrName_ = null;
		// attrValue_ = null;
		// attrSearchkey_ = null;
		// attrSegment_ = null;
		// relaEnable_ = null;
		// relaDisable_ = null;
		// relaVisible_ = null;
		// relaInvisible_ = null;
		// paint_ = null;
	}

	public void setForm(FormLayout formLayout) {
		// TODO Auto-generated method stub
		formLayout_ = formLayout;
	}

	public FormLayout getForm() {
		// TODO Auto-generated method stub
		return formLayout_;
	}

	@Override
	public void setEncrypt(String encrypt) {
		// TODO Auto-generated method stub
		isEncrypt_ = encrypt;
	}
}
